package com.quxiu.common.core.utils.map;

import com.alibaba.fastjson2.JSONObject;

/**
 * 平面直角坐标系工具类
 */
public class PlaneCoordinateSysUtils {

    /**
     * 已知角色坐标系上的2点坐标，A(x1, y1)和B(x2, y2)，及AB这条线上点C与点A距离，求点C位置。
     * @param x1
     * @param y1
     * @param x2
     * @param y2
     * @param dist 距离
     * @return
     */
    public static Point calculatePassPoint(double x1, double y1, double x2, double y2, double dist) {
        // 计算AB两点间的距离
        double length = Math.abs(Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2)));
        System.out.println("length = " + length);

        double x = x1 + (x2 - x1) / length * dist;
        double y = y1 + (y2 - y1) / length * dist;
        Point c = new Point(x, y, length);
        return c;
    }

    public static void main(String[] args) {

        Point c = null;
        c = calculatePassPoint(0, 0, 3, 4, 2.5);
        System.out.println(JSONObject.toJSONString(c));

    }
}
